import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {Observable} from "rxjs";
import {DBBackup, DBBackupCreate, DBBackupDelete, DBBackupUpdate} from "../models/backup";
import {environment} from "../../../../environments/environment";

@Injectable({
  providedIn: 'root'
})
export class BackupService {

  constructor(private http: HttpClient) { }

  createDBBackup(data: DBBackupCreate): Observable<DBBackup>{
    return this.http.post<DBBackup>(`http://${environment.apiServer}/database/backup/`, data);
  }
  deleteDBBackup(data: DBBackupDelete): Observable<string>{
    return this.http.delete<string>(`http://${environment.apiServer}/database/backup/`);
  }
  updateDBBackup(data: DBBackupUpdate): Observable<DBBackup>{
    return this.http.put<DBBackup>(`http://${environment.apiServer}/database/backup/`, data);
  }
  listDBBackup(start: string, end: string): Observable<DBBackup[]>{
    return this.http.get<DBBackup[]>(`http://${environment.apiServer}/database/backups/?start=${start}&end=${end}`);
  }
}
